package com.etrans.web.gps.business.base.service;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.etrans.web.gps.base.service.BaseService;
import com.etrans.web.gps.business.base.domain.CertificateType;
import com.etrans.web.gps.business.base.domain.Driver;
import com.etrans.web.gps.business.base.domain.DriverType;


;

/**
 * 司机信息数据交互层
 * @author liurong
 *
 */
@Service
public class DriverService extends BaseService {
	
	/**
	 * 查询所有的司机信息树
	 * @param param
	 * @return
	 */
	public List<Driver> loadAllDriverTrees(HashMap<String, Object> param){
		
		List<Driver> selectList = selectList("driverQuery.loadAllDriverTrees", param);
		return selectList;
	}
	
	/**
	 * 保存所有司机信息
	 * @param driver
	 */
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,
			Exception.class })
	public void saveDriver(Driver driver) {
		insert("driverMapper.saveDriver", driver);
	}
	
	/**
	 * 修改司机信息
	 * @param driver 
	 */
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,
			Exception.class })
	public void updateDriver( Driver driver) {
		update("driverMapper.updateDriver", driver);
	}
	
	
	/**
	 * 删除司机信息
	 * @param id 司机ID
	 */
	@Transactional(readOnly = false, rollbackFor = { DataAccessException.class,
			Exception.class })
	public void deleteDriverByID(Integer id) {
		delete("driverMapper.deleteDriverByID", id);
	}
	
	
	/**
	 * 根据ID获取司机信息
	 * @param id
	 * @return
	 */
	public Driver queryDriverById( Integer id) {
		Driver driver = (Driver) selectOne("queryDriverById", id);
		//oldDriverMap.put("oldDriver", driver);
		return driver;
	}
	
	/**
	 * 查询所有司机信息
	 * @param param
	 * @return
	 */
	public List<Driver> queryAllDrivers( Map<String, Object> param) {
		List<Driver> selectList = selectList("driverQuery.queryAllDrivers", param);
		return selectList;
	}
	
	/**
	 * 获取所有驾驶证类型
	 * @return
	 */
	public List<DriverType> queryAllDriverTypes(String dbKey) {
		List<DriverType> selectList = selectList("driverQuery.queryAllDriverTypes",1);
		return selectList;
	}
	
	/**
	 * 查询所有的从业资格证类别
	 * @return 
	 */
	public List<CertificateType> queryAllCertificateTypes(String dbKey){
		List<CertificateType> selectList = selectList("driverQuery.queryAllCertificateTypes",1);
		return selectList;
	}
	
	/**
	 * 
	 * @param param
	 * @return
	 */
	public int driverCount( Map<String, Object> param) {
		return (int) this.selectOne("driverQuery.driverCount", param);
	}
	
	
}
